package io.renren.modules.merchant.controller;

import io.renren.common.utils.R;
import io.renren.modules.dishes.entity.MerchantEntity;
import io.renren.modules.merchant.entity.MerchantStatistic;
import io.renren.modules.merchant.service.impl.MerchantServiceImpl;
import io.renren.modules.merchant.service.impl.StatisticsImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static io.renren.common.utils.ShiroUtils.getUserId;

@RestController
@RequestMapping("/web/statistic")
public class StatisticsController {

    @Autowired
    private StatisticsImpl statistics;

    @Autowired
    private MerchantServiceImpl merchantService;


    @GetMapping("/today")
    public R getToday(){
        Long userId = getUserId();
        MerchantEntity merchantByUserId = merchantService.getMerchantByUserId(userId);
        MerchantStatistic today = statistics.getToday(merchantByUserId.getMerchantId());
        return R.ok().put("today",today);
    }

    @GetMapping("/month")
    public R refresh(){
        Long userId = getUserId();
        MerchantEntity merchantByUserId = merchantService.getMerchantByUserId(userId);
        List<MerchantStatistic> month = statistics.getMonth(merchantByUserId.getMerchantId());
        return R.ok().put("month",month);
    }

    @GetMapping("/month/entire")
    public R refreshToday(){
        Long userId = getUserId();
        MerchantEntity merchantByUserId = merchantService.getMerchantByUserId(userId);
        MerchantStatistic month = statistics.getMonthEntire(merchantByUserId.getMerchantId());
        return R.ok().put("month",month);
    }

}
